<%@page import="com.zhuoshi.bean.ContractReportBean"%>
<%@page import="com.zhuoshi.dao.ContractReportDao"%>
<%@page import="com.zhuoshi.bean.CustomerBean"%>
<%@page import="com.zhuoshi.dao.CustomerDao"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
request.setCharacterEncoding("UTF-8");
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

//绑定客户信息
CustomerDao custDao = new CustomerDao();
List<CustomerBean> custList = custDao.getAllList();
pageContext.setAttribute("custList", custList);

ContractReportDao dao = new ContractReportDao();
List<ContractReportBean> list = dao.getList();
session.setAttribute("list", list);
%>

<!DOCTYPE html>
<html>

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no">
    <meta http-equiv="Cache-Control" content="no-siteapp">
    <!--[if lt IE 9]>
<script type="text/javascript" src="lib/html5.js"></script>
<script type="text/javascript" src="lib/respond.min.js"></script>
<script type="text/javascript" src="lib/PIE_IE678.js"></script>
<![endif]-->
    <link rel="stylesheet" type="text/css" href="template/H-ui.min.css">
    <link rel="stylesheet" type="text/css" href="template/H-ui.admin.css">
    <link rel="stylesheet" type="text/css" href="template/iconfont.css">
    <link rel="stylesheet" type="text/css" href="template/icheck.css">
    <link rel="stylesheet" type="text/css" href="template/skin.css" id="skin">
    <link rel="stylesheet" type="text/css" href="template/style.css">
    <!--[if IE 6]>
<script type="text/javascript" src="http://lib.h-ui.net/DD_belatedPNG_0.0.8a-min.js" ></script>
<script>DD_belatedPNG.fix('*');</script>
<![endif]-->
    <title>销售综合报表</title>
    <link rel="stylesheet" href="template/layer.css" id="layui_layer_skinlayercss">
    <link href="template/WdatePicker.css" rel="stylesheet" type="text/css">
</head>

<body>

    <nav class="breadcrumb"><i class="Hui-iconfont"></i> 首页 <span class="c-gray en">&gt;</span> 系统管理 <span class="c-gray en">&gt;</span> 销售综合报表 </nav>
    <div class="page-container">
        <form action="" method="post">
            <div class="text-c"> 销售日期范围：
                <input type="text" name="bdate" onFocus="WdatePicker({maxDate:&#39;#F{$dp.$D(\&#39;datemax\&#39;)||\&#39;%y-%M-%d\&#39;}&#39;})" id="datemin" class="input-text Wdate" style="width:120px;"> -
                <input type="text" name="edate" onFocus="WdatePicker({minDate:&#39;#F{$dp.$D(\&#39;datemin\&#39;)}&#39;,maxDate:&#39;%y-%M-%d&#39;})" id="datemax" class="input-text Wdate" style="width:120px;">
                <input type="text" class="input-text" style="width:120px" placeholder="输入用户简称" id="clientshort" name="clientshort">
                <input type="text" class="input-text" style="width:120px" placeholder="输入备件名称" id="spare" name="spare">
                <button type="submit" class="btn btn-success radius" id="" name=""><i class="Hui-iconfont"></i> 搜销售报表</button>
                <button type="button" name="" class="btn btn-primary radius" onclick="exportToExcel()"><i class="Hui-iconfont"></i> 导出销售报表 </button>
            </div>
        </form>

        <div class="cl pd-5 bg-1 bk-gray mt-20">
            <div class="mt-20">
                <div id="DataTables_Table_0_wrapper" class="dataTables_wrapper no-footer">
                    <table class="table table-border table-bordered table-hover table-bg table-sort dataTable no-footer" id="DataTables_Table_0" role="grid" aria-describedby="DataTables_Table_0_info">
                        <thead>
                            <tr class="text-c" role="row">
                                <th width="80" class="sorting_disabled" rowspan="1" colspan="1" aria-label="排序" style="width: 115px;">排序</th>
                                <th width="80" class="sorting_desc" tabindex="0" aria-controls="DataTables_Table_0" rowspan="1" colspan="1" aria-sort="descending" aria-label="合同编号: 升序排列" style="width: 115px;">合同编号</th>
                                <th width="80" class="sorting" tabindex="0" aria-controls="DataTables_Table_0" rowspan="1" colspan="1" aria-label="备件名称: 升序排列" style="width: 115px;">备件名称</th>
                                <th width="80" class="sorting" tabindex="0" aria-controls="DataTables_Table_0" rowspan="1" colspan="1" aria-label="所属客户: 升序排列" style="width: 115px;">所属客户</th>
                                <th width="80" class="sorting_disabled" rowspan="1" colspan="1" aria-label="备件规格" style="width: 116px;">备件规格</th>
                                <th width="80" class="sorting" tabindex="0" aria-controls="DataTables_Table_0" rowspan="1" colspan="1" aria-label="备件数量: 升序排列" style="width: 116px;">备件数量</th>
                                <th width="80" class="sorting" tabindex="0" aria-controls="DataTables_Table_0" rowspan="1" colspan="1" aria-label="售价: 升序排列" style="width: 116px;">售价</th>
                                <th width="80" class="sorting" tabindex="0" aria-controls="DataTables_Table_0" rowspan="1" colspan="1" aria-label="销售时间: 升序排列" style="width: 116px;">销售时间</th>
                                <th width="80" class="sorting" tabindex="0" aria-controls="DataTables_Table_0" rowspan="1" colspan="1" aria-label="总金额: 升序排列" style="width: 116px;">总金额</th>
                            </tr>
                        </thead>
                        <tbody>


















							<c:forEach items="${list }" var="bean">
                            <tr class="text-c even" role="row">

                                <td>${bean.id }</td>
                                <td class="sorting_1">${bean.numerical }</td>
                                <td>${bean.sqarename }</td>
                                <td>
                                <c:forEach items="${custList }" var="custBean">
                                <c:if test="${custBean.id==bean.customerid }">
                                ${custBean.custname }
                                </c:if>
                                </c:forEach>
                               
                                
                                </td>
                                <td>${bean.modeltype }</td>
                                <td>${bean.totalcount }</td>
                                <td>${bean.price }</td>
                                <td>${bean.condate }</td>
                                <td>${bean.totalmoney }</td>
                            </tr>
                           </c:forEach>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
        <footer class="footer mt-20">
            <div class="container">
                Copyright © 本后台系统由KEG提供技术支持
            </div>
        </footer>
        <script type="text/javascript" src="template/jquery.min.js"></script>
        <script type="text/javascript" src="template/layer.js"></script>
        <script type="text/javascript" src="template/laypage.js"></script>
        <script type="text/javascript" src="template/WdatePicker.js"></script>
        <script type="text/javascript" src="template/jquery.dataTables.min.js"></script>
        <script type="text/javascript" src="template/H-ui.js"></script>
        <script type="text/javascript" src="template/H-ui.admin.js"></script>
        <script type="text/javascript">
            $('.table-sort').dataTable({
                "aaSorting": [
                    [1, "desc"]
                ], //默认第几个排序
                "bStateSave": true, //状态保存
                "aoColumnDefs": [
                    //{"bVisible": false, "aTargets": [ 3 ]} //控制列的隐藏显示
                    {
                        "orderable": false,
                        "aTargets": [0, 4]
                    } // 制定列不参与排序
                ]
            });
            /*系统-栏目-添加*/
            function system_category_add(title, url, w, h) {
                layer_show(title, url, w, h);
            }
            /*系统-栏目-编辑*/
            function system_category_edit(title, url, id, w, h) {
                layer_show(title, url, w, h);
            }
            /*系统-栏目-删除*/
            function system_hetong_del(obj, id) {
                layer.confirm('确认要删除吗？', function(index) {
                    $(obj).parents("tr").remove();
                    document.getElementById("id").value = id;
                    document.form1.submit();
                    layer.msg('已删除!', {
                        icon: 1,
                        time: 1000
                    });
                });
            }
        </script>

    </div>
    <a href="javascript:void(0)" class="Hui-iconfont toTop" title="返回顶部" alt="返回顶部" style="display:none"></a>
    
    
    
    <script>
var idTmr;
function getExplorer() {
    var explorer = window.navigator.userAgent ;
    //ie 
    if (explorer.indexOf("MSIE") >= 0) {
        return 'ie';
    }
    //firefox 
    else if (explorer.indexOf("Firefox") >= 0) {
        return 'Firefox';
    }
    //Chrome
    else if(explorer.indexOf("Chrome") >= 0){
        return 'Chrome';
    }
    //Opera
    else if(explorer.indexOf("Opera") >= 0){
        return 'Opera';
    }
    //Safari
    else if(explorer.indexOf("Safari") >= 0){
        return 'Safari';
    }
}

function exportToExcel( ) {//整个表格拷贝到EXCEL中
    if(getExplorer()=='ie'){
        var curTbl = document.getElementById("DataTables_Table_0");
        var oXL = new ActiveXObject("Excel.Application");

        //创建AX对象excel 
        var oWB = oXL.Workbooks.Add();
        //获取workbook对象 
        var xlsheet = oWB.Worksheets(1);
        //激活当前sheet 
        var sel = document.body.createTextRange();
        sel.moveToElementText(curTbl);
        //把表格中的内容移到TextRange中 
        sel.select;
        //全选TextRange中内容 
        sel.execCommand("Copy");
        //复制TextRange中内容  
        xlsheet.Paste();
        //粘贴到活动的EXCEL中       
        oXL.Visible = true;
        //设置excel可见属性

        try {
            var fname = oXL.Application.GetSaveAsFilename("Excel.xls", "Excel Spreadsheets (*.xls), *.xls");
        } catch (e) {
            print("Nested catch caught " + e);
        } finally {
            oWB.SaveAs(fname);
            oWB.Close(savechanges = false);
            //xls.visible = false;
            oXL.Quit();
            oXL = null;
            //结束excel进程，退出完成
            //window.setInterval("Cleanup();",1);
            idTmr = window.setInterval("Cleanup();", 1);
        }
    }else{
        tableToExcel("DataTables_Table_0");
    }
}

function Cleanup() {
    window.clearInterval(idTmr);
    CollectGarbage();
}

var tableToExcel = (function() {
    var uri = 'data:application/vnd.ms-excel;base64,',
        template = '<html xmlns:o="urn:schemas-microsoft-com:office:office" '
            +'xmlns:x="urn:schemas-microsoft-com:office:excel" '
            +'xmlns="http://www.w3.org/TR/REC-html40 ">'
            +'<head>'
            +'<!--[if gte mso 9]>'
            +'<xml>'
            +'<x:ExcelWorkbook>'
            +'<x:ExcelWorksheets>'
            +'<x:ExcelWorksheet>'
            +'<x:Name>{worksheet}</x:Name>'
            +'<x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions>'
            +'</x:ExcelWorksheet>'
            +'</x:ExcelWorksheets>'
            +'</x:ExcelWorkbook>'
            +'</xml>'
            +'<![endif]-->'
            +'</head>'
            +'<body><table>{table}</table></body>'
            +'</html>',
            
    base64 = function(s) { return window.btoa(unescape(encodeURIComponent(s))) };
    format = function(s, c) {
        return s.replace(/{(\w+)}/g,
        function(m, p) { return c[p]; }) };
    
        return function(table, name) {
            if (!table.nodeType) table = document.getElementById(table);
            var ctx = {worksheet: name || 'Worksheet', table: table.innerHTML};
            window.location.href = uri + base64(format(template, ctx));
        }
    })()

</script>
    
</body>

</html>